#coding:utf-8
from rest_framework import serializers
from blog.models import *

class BlogSerializer(serializers.ModelSerializer):
   owner = serializers.ReadOnlyField(source='owner.name') #只读
   class Meta:
       model = Blog
       fields = ('id', 'title', 'body', 'owner')


#用于注册的时候返回json数据

class UserRegisterSerializer(serializers.ModelSerializer):
   class Meta:
       model = User
       #fields = ('id', 'username', 'name')

class UserSerializer(serializers.ModelSerializer):
   blog_set = serializers.PrimaryKeyRelatedField(many=True, queryset=Blog.objects.all())
   class Meta:
       model = User
       #fields = ('id', 'username', 'blog_set')